<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@include file="he_includePackage.jsp"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>


<body>
<style>
.col-xs-3 {
	padding: 1px;
	height: 1000px;
}

.col-xs-9 {
	height: 1000px;
}

.container {
	width: 1280px !important;
}

.xs11 {
	margin-top: 20px;
	margin-left: 30px;
}

#xs12 {
	height: 894px;
	width: 313px;
}

#xs13 {
	height: 120px;
	width: 600px
}

#xs11 {
	height: 140px;
}

#xs10 {
	height: 110px;
}

#xs1 {
	height: 100px;
	width: 80px;
}

body {
	font-size: 12px;
}

ul {
	margin: 0;
	padding: 7px;
}

ul li {
	height: 22px;
	vertical-align: bottom;
}

td {
	text-align: center;
}

th {
	text-align: center;
}

.actived {
	height: 40px;
	border-top: 3px solid #ff9900;;
	border-right: 1px solid #AAC7E9;
	border-left: 1px solid #AAC7E9;
	border-bottom: 1px solid #AAC7E9;
	background: #FFDAB9;
}

.panel-group {
	padding: 1px;
	margin：1px;
}

nav {
	text-align: center;
}
</style>
<script type="text/javascript" language="javascript">
function g(o){return document.getElementById(o);}
function hoverli(n){
for(var i=1;i<25;i++){
{g('tb_'+i).className='';}
g('tb_'+n).className='actived';}
};
/* $.ajax({
    	url:'${pageContext.request.contextPath}/TeaStu',
    	type:'get',
    	async:false,//此处必须是同步
    	dataTye:'json',
    	success:function(data){
    	comboboxData=data;
    	}
    })*/
//课题来源格式转换
var dissertation;//论文题目
var editRow=undefined;
var dissType = [ { "value": "设计", "text": "设计","id": "1" }, { "value": "论文", "text": "论文" ,"id": "1"}];
var dissMethod = [ { "value": "盲选", "text": "盲选","id": "1" }, { "value": "指定学生", "text": "指定学生" ,"id": "1"}];
var source_formatter;
$(function(){//处理来源的格式
	$.ajax({
		url:'${pageContext.request.contextPath}/thesissource',
    	type:'post',
    	dataTye:'json',
    	success:function(j){
				source_formatter=j;
    		} 
		 });
})
$(function() {
			dissertation = $("#dissertation").datagrid({
			url:'<%=request.getContextPath()%>/index',
			title : '教师申报的论文课题(不包含学生提交的课题)',
			resizeable:true,
			pageSize: 10,//每页显示的记录条数，默认为10 
       		pageList: [5,10,15],//可以设置每页记录条数的列表 
			pagination : true,
			singleSelect : true,
			sortName : 'id',
			sortOrder : 'desc',
			//fit : true,
			//nowrap:false,
			fitColumns : true,
			striped:true,
			columns : [ [ {
				field : 'id',
				title : 'id',
				width : 50,
				sortable : true,
				checkbox:true,
			}, {
				field : 'thesistitle_name',
				title : '课题名称',
				width : 150,
				editor:{
				type:'validatebox',
				options:{
				required:true,
					}
				}
			}, {
				field : 'thesistitle_type',
				title : '类型',
				width : 50,
				editor: {
				type: 'combobox',
				options: { 
				panelHeight : 'auto',
				editable:false,
				method:'post',
				url:'${pageContext.request.contextPath}/dissType',
				valueField:'value', 
				textField:'text',
				required:true, }
				 }
			}, {
				field : 'thesistitle_source',
				title : '来源',
				formatter: function(value,row,index){
					for(var i in source_formatter){
						if(source_formatter[i].thesissource_id==value){
							res=source_formatter[i].thesissource_name;
						}
					}
			        return res;
				},
				editor: {
					type: 'combobox',
					options: { 
					panelHeight : 'auto',
					editable:false,
					method:'post',
					url:'${pageContext.request.contextPath}/thesissource',
					valueField:'thesissource_id', 
					textField:'thesissource_name',
					required:true, 
					}
					 },
				
				width : 100
			}, {
				field : 'thesistitle_select_way',
				title : '选题方式',
				width : 100,
				formatter: function(value,row,index){
					if (value=='A'){
						return '学生申请';
					} ;
					if (value=='B'){
						return '盲选';
					} ;
					if(value=='C'){
						return '指定学生';
					}
				},
				editor: {
					type: 'combobox',
					//value:'test',
					options: { 
					panelHeight : 'auto',	
					editable:false,
					//data:dissMethod,
					method:'post',
					url:'${pageContext.request.contextPath}/method',
					valueField:'value', 
					textField:'text',
					required:true,
					onSelect : function(record) {
						
					if(record.value=="C"||record.value=="指定学生"){
						var ed = $("#dissertation").datagrid('getEditor', {
							index :editRow,
							field : 'Sin',
							required:true,
						});
						var url = '${pageContext.request.contextPath}/TeaStu';
						$(ed.target).combobox('reload', url);
						$(ed.target).combobox('clear');
						
					
				
					}
					if(record.value=="B"||record.value=="盲选"){
						var ed = $("#dissertation").datagrid('getEditor', {
							index : editRow,
							field : 'Sin',
							disabled :false,
						});
						$(ed.target).combobox('loadData', {});
						$(ed.target).combobox('clear');
					}
				}
					},
					
					 },
			
			},{
				field : 'Sin',
				title : '选题学生',
				width : 100,
				editor: {
					type: 'combobox',
					options: {
					panelHeight : 'auto',
					editable:false,
					method:'post',
					url:'',
					//url:'${pageContext.request.contextPath}/TeaStu',
					valueField:'student_id', 
					textField:'Sin',
					}
					 }
			},{
				field : 'thesistitle_selected',
				title : '选择状态',
				width : 100,
				formatter: function(value,row,index){
					if(value=='A'){
						return '已被选';
					}
					if(value=='B'){
						return '未被选';
					}
				},
				
			},{
				field : 'thesistitle_checkstate',
				title : '审核状态',
				width : 100,
				formatter: function(value,row,index){
					if (value=='A'){
						return '未审核';
					} ;
					if(value=='B'){
						return '指导教师审核未通过';
					};
					if(value=='C'){
						return '指导教师审核通过';
					};
					if(value=='D'){
						return '修改通过';
					};
					if(value=='E'){
						return '专业负责人审核未通过';
					};
					if(value=='F'){
						return '专业负责人审核通过';
					};
					if(value=='G'){
						return '教务审核未通过';
					};
					if(value=='H'){
						return '教务审核通过';
					};
				},
			},
				
			] ],
        	toolbar: ['-',{
        		 text: '添加课题', 
            iconCls: 'icon-add', 
            handler: function(){ 
              $('#dd').dialog({    
   				 title: '申报论文课题1',    
    						width: 400,    
    						height: 200,    
    						closed: false,    
    						cache: false,    
    						href: '${pageContext.request.contextPath}/pages1/add.jsp',    
   						 	modal: true,
   						 	
							}); 
            } 
        	},{
            text: '修改', 
            iconCls: 'icon-edit', 
            handler: function() { 
            	
                var rows=dissertation.datagrid('getSelections');
                if(rows.length==1){
                	if(editRow != undefined){
                        dissertation.datagrid('endEdit',editRow);
                        }
                	//开启编辑状态
            		if(editRow == undefined){
                    	var index=dissertation.datagrid('getRowIndex',rows[0]);
               			dissertation.datagrid('beginEdit',index);
               			dissertation.datagrid('unselectAll');//取消所有选中的行
               			editRow=index;
                		} 
                }
            } 
        }, '-',{ 
            text: '删除', 
            iconCls: 'icon-remove', 
            handler: function(){ 
            	var rows=dissertation.datagrid('getSelections');
            	if(rows.length>0){
            		console.info(rows);
            		$.messager.confirm('请确认','您真的要删除选中的项吗',function(r){
            			if(r){
                        	$.ajax({
                        		url:'${pageContext.request.contextPath}/delete',
                            	data:"student_id="+rows[0].student_id+"&thesistitle_id="+rows[0].thesistitle_id+"&thesistitle_select_way="+rows[0].thesistitle_select_way,
                            	//data:rows,
                            	type:'post',
                            	dataTye:'json',
                            	success:function(){
                            		console.info("删除成功");
                            		$('#dissertation').datagrid('load');
                            	} 
                        	 }) 
        				 }
            			else{
                            $.messager.alert('提示','请选择要删除的记录');
                            }
            		})
            	}
               
            }
        }, '-',{ 
            text: '保存', 
            iconCls: 'icon-save', 
            handler: function(){ 
                dissertation.datagrid('endEdit',editRow);
            } ,
        }, '-',{ 
            text: '取消编辑', 
            iconCls: 'icon-redo', 
            handler: function(){ 
               editRow=undefined;
               dissertation.datagrid('unselectAll');//取消所有选中的行
               dissertation.datagrid('rejectChanges');//回滚
            } , 
           },
        ], 
        rowStyler: function(index,row){
    		if(index%2==0){
        		return 'background-color:rgb(230,230,230);height:30px';
    		}
    		else{
	    		return 'height:30px;';

			}
        },
        //结束编辑之后触发
        onAfterEdit:function(rowIndex,rowData,changes){
        	var url='';
        	var updated=dissertation.datagrid('getChanges','updated');
        	if (updated.length>0){
       			url='${pageContext.request.contextPath}/updated';
       		}
        	$.ajax({
        	url:url,
        	//data:"dissType="+rowData.dissType+"&dissName="+rowData.dissName+"&Sin="+rowData.Sin,
        	//data:"rowData="+rowData,
        	data:rowData,
        	type:'post',
        	//async:false,//此处必须是同步
        	dataTye:'json',
        	success:function(data){
        		$('#dissertation').datagrid('load');
        	comboboxData=data;
        	editRow=undefined;
        	}
      	  }) 
       	 }
				});
		})
		
		function showWhat()
		{
			var collap=document.getElementById('collapseHelp');
			if(collap.style.display=='none')
				collap.style.display='block';
			else
				collap.style.display='none';
		}	
</script>

		<div class="row">
			<div class="row">
				<div class="col-xs-12  xs11">
					<strong><font size="3">流程管理》申报课题</font>
					</strong>
				</div>
			</div>
			<div class="col-xs-11  xs11">
				<div class="panel panel-default">
					<div class="panel-heading" align="left">
						<a data-toggle="collapse" data-parent="#accordion"
							href="#collapseHelp" class="glyphicon glyphicon-chevron-down" onclick="showWhat()">
							操作指南 </a>
					</div>
					<div id="collapseHelp" class="panel-collapse collapse">
						<div class="panel-body">
							学生论文课题，采用以下3种情况进行论文题目的申报：
							<ul>
								<li>可以学生自己拟定题目，然后申报论文题目；</li>
								<li>论文题目可以由实习单位负责人给学生提供，然后由学生提交申报该论文题目；</li>
								<li>论文题目由指导教师提供，由学生从指导教师提供的论文题目中选择一个题目进行论文的撰写工作。</li>
							</ul>
							在指导教师审核通过后，分配给指定学生，将该论文题目作文开题报告论文题目，论文题目在指导教师审核阶段可以进行修改，当申报的题目在专业负责人审批通过后，一般不可以修改了。
						</div>
					</div>
				</div>
			</div>
		</div>

		<hr />
		<div style="height:230px;width:900px;" >
        		<table  id="dissertation"  ></table>
        </div>
       <div style="height:100px;width:100%;"></div> 
        <div class="panel panel-default">
           <div id="dd"></div>  
          </div> 
         

</body>
</html>
